//
//  ZZThemeCellModel.m
//  ZZBlue
//
//  Created by stonesMonkey on 2017/9/21.
//  Copyright © 2017年 stonesMonkey. All rights reserved.
//

#import "ZZThemeCellModel.h"
#import "ZZColorRGBA.h"
@implementation ZZThemeCellModel
- (instancetype)init {

    if (self = [super init]) {

        self.pinLv = 0.5;
        self.lightValue = 0.5;
    }
    return self;
}

-(void)encodeWithCoder:(NSCoder *)aCoder
{
    [aCoder encodeInteger:self.modelStyle forKey:@"modelStyle"];
    [aCoder encodeObject:self.title forKey:@"title"];
    [aCoder encodeObject:self.colors forKey:@"colors"];
    [aCoder encodeObject:self.imageStr forKey:@"imageStr"];
    [aCoder encodeFloat:self.pinLv forKey:@"pinLv"];
    [aCoder encodeFloat:self.lightValue forKey:@"lightValue"];
}

-(instancetype)initWithCoder:(NSCoder *)aDecoder
{
    if (self = [super init]) {
        
        self.modelStyle = [aDecoder decodeIntegerForKey:@"modelStyle"];
        _title = [aDecoder decodeObjectForKey:@"title"];
        self.colors = [NSMutableArray arrayWithArray:[aDecoder decodeObjectForKey:@"colors"]];
        self.imageStr = [aDecoder decodeObjectForKey:@"imageStr"];
        _pinLv = [aDecoder decodeFloatForKey:@"_pinLv"];
        self.lightValue = [aDecoder decodeFloatForKey:@"lightValue"];
    }
    return self;
}

- (void)equalToModel:(ZZThemeCellModel *)model {
    
    self.modelStyle = model.modelStyle;
    self.title = model.title;
    self.imageStr = model.imageStr;
    self.colors = [NSMutableArray arrayWithArray:model.colors];
    self.pinLv = model.pinLv;
    self.lightValue = model.lightValue;
}

- (void)imageAndTitleForModel:(ThemeLightModel)model {
    
    
    switch (model) {
        case 0:
            _imageStr = @"img_theme01";
            _title = @"欢乐海岸(主题样式一)";
            break;
        case 1:
            _imageStr = @"img_theme02";
            _title = @"年复一年(主题样式二)";
            break;
        case 2:
            _imageStr = @"img_theme03";
            _title = @"浪漫温柔(主题样式三)";
            break;
        case 3:
            _imageStr = @"img_theme04";
            _title = @"我爱永恒(主题样式四)";
            break;
        case 4:
            _imageStr = @"img_theme05";
            _title = @"波纹(主题样式五)";
            break;
        default:
            _imageStr = @"img_theme01";
            _title = @"欢乐海岸(主题样式一)";
            break;
    }
    
}

- (NSMutableArray<ZZColorRGBA *> *)colors {
    
    if (!_colors) {
        
        _colors = [NSMutableArray array];
    }
    return _colors;
}

- (void)setModelStyle:(ThemeLightModel)modelStyle {
    
    _modelStyle =  modelStyle;
     [self imageAndTitleForModel:modelStyle];
}

- (BOOL)isEqualToModel:(ZZThemeCellModel *)model {
    
    if (model.modelStyle != self.modelStyle) {
        
        return NO;
    }
    
    if (![model.title isEqualToString:self.title]) {
        return NO;
    }
    
    if (![model.imageStr isEqualToString:self.imageStr]) {
        
        return NO;
    }
    
    if (model.lightValue != self.lightValue) {
        
        return NO;
    }
    
    if (model.pinLv != self.pinLv) {
        
        return NO;
    }
    
    if (self.colors.count != model.colors.count) {
        
        return NO;
    }
    
    for (NSInteger index = 0; index < self.colors.count; index++) {
        
        ZZColorRGBA *selfRGBA = self.colors[index];
        ZZColorRGBA *modelRGBA = model.colors[index];
        if (selfRGBA.R != modelRGBA.R || selfRGBA.G != modelRGBA.G || selfRGBA.B != modelRGBA.B || selfRGBA.A != modelRGBA.A) {
            
            return NO;
        }
    }
    
    return YES;
    
//    @property (nonatomic, assign)ThemeLightModel modelStyle;
//
//    @property (nonatomic, copy)NSString *title;
//
//    @property (nonatomic, copy)NSString *imageStr;
//
//    @property (nonatomic, strong)NSMutableArray<ZZColorRGBA *> *colors;
//
//    - (void)isEqualToModel:(ZZThemeCellModel *)model;

}



@end
